package 题目集.图.最短路;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Dijkstra序列前向星 {
    static int maxN = 1001;
    static int maxM = 1001;
    static int[] h = new int[maxN];
    static int[] ne = new int[maxM];
    static int[] _to = new int[maxM];
    static int[] _w = new int[maxM];
    static int idx=1;
    static int n, m;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int from = sc.nextInt();
            int to = sc.nextInt();
            int w = sc.nextInt();
            add(from, to, w);
            add(to, from, w);
        }
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int[] path = new int[n + 1];
            for (int j = 1; j < path.length; j++) {
                path[j] = sc.nextInt();
            }
            int[] dis = dijkstra(path[1]);
            int pre = -1;
            boolean flag = true;
            for (int j = 1; j <= n; j++) {
                int cur = dis[path[j]];
                if (cur < pre) {
                    flag = false;
                    break;
                }
                pre = cur;
            }
            if (flag) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

    private static int[] dijkstra(int s) {
        int[] dis = new int[n + 1];
        Arrays.fill(dis,Integer.MAX_VALUE);
        boolean[] vis = new boolean[n + 1];
        PriorityQueue<int[]> queue = new PriorityQueue<>((a, b) -> a[1] - b[1]);
        queue.add(new int[]{s, 0});
        int cnt = 0;
        dis[s]=0;
        while (!queue.isEmpty() && cnt < n) {
            int[] poll = queue.poll();
            int id = poll[0];
            int d = poll[1];
            if (vis[id]) continue;
            vis[id]=true;
            cnt++;
            for (int next = h[id]; next != 0; next = ne[next]) {
                int to = _to[next];
                int w = _w[next];
                int newD = d + w;
                if (newD < dis[to]) {
                    dis[to]= newD;
                    queue.add(new int[]{to, newD});
                }
            }
        }
        return dis;
    }

    public static void add(int f, int t, int w) {
        _to[idx] = t;
        _w[idx] = w;
        ne[idx] = h[f];
        h[f]=idx++;
    }
}
